
package com.hulk.dryad.common.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.EnumSet;

/**
 * @author kim
 * @date 2018/9/30 资源类型
 */
@Getter
@AllArgsConstructor
public enum ResourceType {


	/**
	 * 图片资源
	 */
	IMAGE("image", "ResourceType_IMAGE"),

	/**
	 * xml资源
	 */
	XML("xml", "ResourceType_XML");

	/**
	 * 类型
	 */
	private final String type;

	/**
	 * 描述
	 */
	private final String description;


	ResourceType(String type, String description) {
		this.type = type;
		this.description = description;
	}

	public String getDesc() {
		return messageSource.getMessage(description, null, description, LocaleContextHolder.getLocale());
	}


	private MessageSource messageSource;

	public ResourceType setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
		return this;
	}


	@Component
	public static class ReportTypeServiceInjector {

		@Resource
		private MessageSource messageSource;

		@PostConstruct
		public void postConstruct() {
			for (ResourceType ec : EnumSet.allOf(ResourceType.class)) {
				ec.setMessageSource(messageSource);
			}
		}
	}

}
